

# 定义2D矩阵
nums=[
    [12,42,43,34,67,89,23,12],
    [23,46,65,34,65,89,23,44],
    [33,64,88,42,56,97,32,47],
    [23,56,97,87,34,20,29,23]
]

def myMap(num):
    # 结果集
    Result={}
    # 数据集
    Each={}
    # 行
    row=len(num)
    # 列
    col=len(num[0])
    for i in range(row):
        for j in range(col):
            Each[(i+1,j+1)]=num[i][j]

    for r in range(1,row-1):
        for c in range(1,col-1):
            Result[(r+1,c+1)]=[
                Each[(r,c)],
                Each[(r,c+1)],
                Each[(r,c+2)],
                Each[(r+1,c)],
                Each[(r + 1, c+2)],
                Each[(r+2,c)],
                Each[(r + 2, c+1)],
                Each[(r + 2, c+2)]
            ]
    return Result

def MyReduce(num,data):
    sum=0
    for i in data[num]:
        sum=sum+i
    return "{}--->{}".format(num,sum/8)

data=myMap(nums)
print(MyReduce((2,2),data))
